export default class Loading {
  constructor (className = 'loading', loadingTxt = 'loading...') {
    const cls = '.' + className
    if (!document.querySelector(cls)) {
      const loadingDom = document.createElement('div')
      loadingDom.className = className
      loadingDom.innerHTML = loadingTxt
      document.body.appendChild(loadingDom)
    }

    this.loadingTxt = loadingTxt
    this.dom = document.querySelector(cls)
  }

  show (txt) {
    this.dom.innerHTML = txt || this.loadingTxt
    this.dom.style.display = ''
  }

  hide () {
    this.dom.style.display = 'none'
  }

  isShow () {
    return this.dom.style.display !== 'none'
  }
}
